/**
 * Display a modal dialog with specified content
 * @param {string} content - The content to display
 * @param {string} [title='提示'] - The title of the modal
 * @param {boolean} [showCancel=false] - Whether to show cancel button
 * @returns {Promise<object>} - Promise resolving to the result of the modal interaction
 */
const uniModal = (content, title = '提示', showCancel = false) => {
  return new Promise((resolve) => {
    wx.showModal({
      title,
      content,
      showCancel,
      success: (res) => {
        resolve(res);
      }
    });
  });
};

/**
 * Format date to specified format
 * @param {Date} date - Date object to format
 * @param {string} fmt - Format string
 * @returns {string} - Formatted date string
 */
const formatTime = (date, fmt = 'YYYY-MM-DD HH:mm:ss') => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();

  return fmt
    .replace('YYYY', year)
    .replace('MM', month.toString().padStart(2, '0'))
    .replace('DD', day.toString().padStart(2, '0'))
    .replace('HH', hour.toString().padStart(2, '0'))
    .replace('mm', minute.toString().padStart(2, '0'))
    .replace('ss', second.toString().padStart(2, '0'));
};

module.exports = {
  uniModal,
  formatTime
}; 